package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.ShareProfitDaoPool;
import com.sc.nft.mapper.ShareProfitDaoPoolMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：DaoEcologyPointsWalletDao
 * @Date：2024/11/26 11:08
 * @Filename：DaoEcologyPointsWalletDao
 */
@Slf4j
@Repository
public class ShareProfitDaoPoolDao extends ServiceImpl<ShareProfitDaoPoolMapper, ShareProfitDaoPool> {

    /**
     * 获取
     *
     * @param ecologyHatchId
     * @return
     */
    public ShareProfitDaoPool getOneByConditions(Long ecologyHatchId, Long collectionId, Long daoId, Long sourceDaoId, Long pointsId, Date now) {
        return baseMapper.getOneByConditions(ecologyHatchId, collectionId, daoId, sourceDaoId, pointsId, now);
    }

    /**
     * 添加冻结金额
     *
     * @param id
     * @param amount
     * @return
     */
    public Boolean addAmount(Long id, BigDecimal amount) {
        return baseMapper.addAmount(id, amount);
    }

    /**
     * @param ecologyHatchId
     * @param sourceDaoId
     * @return
     */
    public List<ShareProfitDaoPool> getListByEcologyHatchIdAndSourceDaoId(Long ecologyHatchId, Long sourceDaoId, Boolean isSettle, Date now) {
        LambdaQueryWrapper<ShareProfitDaoPool> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ShareProfitDaoPool::getEcologyHatchId, ecologyHatchId);
        wrapper.eq(ShareProfitDaoPool::getSourceDaoId, sourceDaoId);
        wrapper.eq(ShareProfitDaoPool::getIsSettle, isSettle);
        wrapper.lt(ShareProfitDaoPool::getEndTime,now);
        return list(wrapper);
    }
    /**
     *  服务中心分账积分
     * @param daoId
     * @param ecologyHatchId
     * @return
     */
    public BigDecimal getAmountServiceCentre(Long daoId, Long ecologyHatchId) {
        return baseMapper.getAmountServiceCentre(daoId, ecologyHatchId);
    }

    public Boolean updateSettle(Long id, Boolean isSettle) {
        LambdaUpdateWrapper<ShareProfitDaoPool> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ShareProfitDaoPool::getId, id);
        wrapper.set(ShareProfitDaoPool::getIsSettle, isSettle);
        return update(new ShareProfitDaoPool(), wrapper);
    }
}
